﻿using FluentScheduler;
using FluentValidation.Mvc;
using log4net.Config;
using QAS.Nekorama.Common;
using System.Globalization;
using System.IO;
using System.Threading;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;

namespace QAS.Nekorama
{
    /// <summary>
    /// MVCアプリケーション
    /// </summary>
    public class MvcApplication : HttpApplication
    {
        /// <summary>
        /// アプリケーションスタート
        /// </summary>
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterAuth();
            TaskManager.Initialize(new BountyChecker());
            FluentValidationModelValidatorProvider.Configure();
            XmlConfigurator.Configure(new FileInfo(Server.MapPath("~/Web.config")));
        }

        /// <summary>
        /// 始めての要求を受け取ります。
        /// </summary>
        protected void Application_AcquireRequestState()
        {
            if (Session["culture"] == null)
            {
                Session["culture"] = "en-US";
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
                Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
            }
            else
            {
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(Session["culture"].ToString());
                Thread.CurrentThread.CurrentCulture = new CultureInfo(Session["culture"].ToString());
            }
        }
    }
}